import numpy as np
import matplotlib.pyplot as plt
from math import *
import pandas as pd
n = 1000
para = np.linspace(1.08, 0, n)
r = 50
# 渐开线参数方程:
x = r * (np.cos(para + 1.082) + para * np.sin(para + 1.082))
y = r * (np.sin(para + 1.082) - para * np.cos(para + 1.082))
# plt.plot(x-x[-1],y-y[-1])
# plt.show()

v = 0.006
# 离散化:
k = 0
vx = np.zeros(n - 1)
vy = np.zeros(n - 1)
time = np.zeros(n)
# 输出矩阵 fvx和fvy是水平和竖直方向速度的分段函数
fvx = np.zeros((n - 1, 3))
fvy = np.zeros((n - 1, 3))
while k <= n - 2:
    s = sqrt((x[k] - x[k + 1]) ** 2 + (y[k] - y[k + 1]) ** 2)
    dt = s / v
    time[k + 1] = time[k] + dt
    dx = x[k+1] - x[k]
    dy = y[k+1] - y[k]
    vx[k] = dx / dt
    vy[k] = dy / dt
    fvx[k, 0] = time[k]
    fvx[k, 1] = time[k + 1]
    fvx[k, 2] = vx[k]
    fvy[k, 0] = time[k]
    fvy[k, 1] = time[k + 1]
    fvy[k, 2] = vy[k]
    k += 1
    pass
print(fvx)
fvx = np.array(fvx)
fvy = np.array(fvy)
from 画图 import *
k=0
A=np.mat([0,0])
while k<=fvx.shape[0]-2:
    dt=fvx[k,1]-fvx[k][0]
    dx=fvx[k,2]*dt
    dy=fvy[k,2]*dt
    B=A[k]+np.mat([dx,dy])
    A=np.append(A,B,axis=0)
    k+=1
    pass
A=A.tolist()
A=np.array(A)
plt.scatter(A[:,0],A[:,1])
plt.show()